<template>
    <a-form-model
            ref="ruleForm"
            :model="form"
            :rules="rules"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
    >
        <a-form-model-item ref="name" label="商品名称" prop="goodsName">
            <a-input disabled v-model="form.goodsName"/>
        </a-form-model-item>

        <a-form-model-item>
            <span slot="label" class="ant-form-item-required">商品图片</span>
            <upload-image disabled
                          v-model="form.goodsPicture"
                          @change="handleProductImageChange">
            </upload-image>
            <div class="desc">尺寸：1000*600像素，小于1M，支持jpg、png、jpeg格式</div>
        </a-form-model-item>

        <a-form-model-item label="库存设置" prop="stock">
            <a-input-number disabled v-model="form.stock" :min="1" :max="5000">

            </a-input-number>
            件
        </a-form-model-item>

        <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
            <a-button disabled type="primary" @click="onSubmit">
                提交
            </a-button>

        </a-form-model-item>
    </a-form-model>
</template>
<script>

    export default {
        components: {

        },
        created() {
          /*  let id = this.$route.query.id
            let url = 'goldenhome/gh/lottery_/admin/giving/goodsmanage/id'
            this.$get(url, {id}).then((res) => {
                if (res && res.returnCode === 1000) {
                    console.log('***********', res)
                    this.form.goodsName = res.dataInfo.goodsName
                    this.form.stock = res.dataInfo.stock
                    this.form.goodsPicture = res.dataInfo.goodsPicture
                }
            })*/
           this.form.goodsName =this.$route.query.goodsName
           this.form.stock =this.$route.query.stock
           this.form.goodsPicture =this.$route.query.goodsPicture
        },
        data() {
            return {
                labelCol: {span: 4},
                wrapperCol: {span: 8},
                form: {
                    goodsName: '',
                    stock: 1,
                    goodsPicture: ''
                },

                rules: {
                    stock: [
                        {required: true, message: '请输入库存', trigger: 'blur'},
                    ],
                    goodsName: [{required: true, message: '请输入商品名称', trigger: 'change'}],
                },
            };
        },
        methods: {
            onSubmit() {
                console.log(this.form);
                this.$refs.ruleForm.validate(valid => {

                    if (valid) {
                        // alert('submit!');
                    } else {
                        // console.log('error submit!!');
                        return false;
                    }
                });
            },
            handleProductImageChange(val) {
                this.form.goodsPicture = val
                console.log(this.form.goodsPicture)
            },
        },
    };
</script>
